import java.io.*;

public class Main1 {
    public static void main(String[] args) throws Exception {
       //创建Book类，成员属性有：书号、书名、作者、价格、出版社、出版年份。
        // 创建该类的10个对象
       Book[] books=new Book[10];
        books[0]=new Book(1,"a","z");
        books[1]=new Book(2,"b","q");
        books[2]=new Book(3,"c","s");
        books[3]=new Book(4,"d","l");
        books[4]=new Book(5,"e","z");
        books[5]=new Book(6,"f","w");
        books[6]=new Book(7,"g","z");
        books[7]=new Book(8,"h","w");
        books[8]=new Book(9,"i","y");
        books[9]=new Book(10,"j","l");

        //（1）使用字节输入输出流将这10个对象存入文件中并读出。
        ObjectOutputStream outputStream=new ObjectOutputStream(new  FileOutputStream("d:/test.txt"));//对象流(写入)
        outputStream.writeObject(books);//写入文件
        ObjectInputStream inputStream=new ObjectInputStream(new FileInputStream("d:/test.txt"));//(读出)
        Book[] books1=null;
        try {
            while (true){
                    books1=(Book[]) inputStream.readObject();
            }
        }catch (EOFException e){
            e.printStackTrace();
        }

        for (int i = 0; i < books1.length ; i++) {
            System.out.println(books[i]);//输出
        }
    }
}